package com.tjsinfo.tjsoa.system.action;

import java.util.ArrayList;
import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;

import com.tjsinfo.tjsoa.system.bo.ISystemAllGroupBO;
import com.tjsinfo.tjsoa.system.vo.TSystemAllgroup;
import com.tjsinfo.tjsoa.system.vo.TSystemUser;
import com.tjsinfo.tjsoa.system.vo.TSystemUserallgroup;

public class AddAllGroupAction  extends Action {
	private ISystemAllGroupBO systemAllGroupBO;
	
	
	
	public ISystemAllGroupBO getSystemAllGroupBO() {
		return systemAllGroupBO;
	}



	public void setSystemAllGroupBO(ISystemAllGroupBO systemAllGroupBO) {
		this.systemAllGroupBO = systemAllGroupBO;
	}



	public ActionForward execute(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response)
			throws Exception {
		// TODO Auto-generated method stub
		List<TSystemUserallgroup> systemUserallgroupList = new ArrayList<TSystemUserallgroup>();
		TSystemAllgroup systemAllgroup = new TSystemAllgroup();
		systemAllgroup.setGroupName(request.getParameter("groupName"));
		systemAllgroup.setOrderNo(Integer.parseInt(request.getParameter("orderNo")));
		systemAllgroup.setState(0);
		String userinfoListId = request.getParameter("renyuanid");
		if (userinfoListId != null && !"".equals(userinfoListId)) {
			String[] userinfoArray = userinfoListId.split(",");
			for (String userid : userinfoArray) {
				if(userid != null && !"".equals(userid)){
					TSystemUser systemUser = new TSystemUser();
					systemUser.setUserId(Integer.parseInt(userid));
					TSystemUserallgroup systemUserallgroup = new TSystemUserallgroup();
					systemUserallgroup.setSystemUser(systemUser);
					systemUserallgroupList.add(systemUserallgroup);
				}
			}
		} else {
			;
		}
		systemAllGroupBO.addSystemAllGroup(systemAllgroup, systemUserallgroupList);
		request.setAttribute("linkurl", "system/allGroup/allgrouplist.jsp");
		request.setAttribute("message", "system.save.message");
		return mapping.findForward("success");
	}
}